package com.lib.common.helper.arouter.mapping;

import com.google.gson.annotations.SerializedName;
import com.lib.framework.utils.GsonUtil;

import java.util.Collections;
import java.util.Map;

/**
 * Created by Zhangjiaxing on 2019/1/4.
 * If there are any problems, please
 * send email to kevin.zhang@xiangwushuo.com
 *
 * @descrpition
 **/
public class PathInfo {
    public static final PathInfo EMPTY = new PathInfo();

    @SerializedName("path")
    private String mPath;
    @SerializedName("code")
    private String mCode;
    @SerializedName("description")
    private String mDescription;
    @SerializedName("extras")
    private Map<String, Object> mExtras;


    public PathInfo() {
        mPath = "";
        mCode = "";
        mExtras = Collections.emptyMap();
    }

    public String getPath() {
        return mPath;
    }

    public void setPath(String path) {
        mPath = path;
    }

    public String getCode() {
        return mCode;
    }

    public void setCode(String code) {
        mCode = code;
    }

    public String getDescription() {
        return mDescription;
    }

    public void setDescription(String description) {
        mDescription = description;
    }

    public Map<String, Object> getExtras() {
        return mExtras;
    }

    public void setExtras(Map<String, Object> extras) {
        mExtras = extras;
    }

    @Override
    public String toString() {
        return GsonUtil.toJson(this);
    }

    public Object getExtra(String key) {
        if (mExtras != null) {
            return mExtras.get(key);
        } else {
            return null;
        }
    }

    public String getStringExtra(String key) {
        Object obj = getExtra(key);
        if (obj instanceof String) {
            return (String) obj;
        } else {
            return "";
        }
    }

    public Integer getIntExtra(String key) {
        Object obj = getExtra(key);
        if (obj instanceof Integer) {
            return (Integer) obj;
        } else {
            return null;
        }
    }

    public Boolean getBooleanExtra(String key) {
        Object obj = getExtra(key);
        if (obj instanceof Boolean) {
            return (Boolean) obj;
        } else {
            return false;
        }
    }

    public Map<String, Object> getMapExtra(String key) {
        Object obj = getExtra(key);
        if (obj instanceof Map) {
            return (Map<String, Object>) obj;
        } else {
            return null;
        }
    }
}
